package jgl.vajra.operator.part.login.viewModel;

import android.text.TextUtils;

import java.util.Map;

import jgl.vajra.operator.part.login.contract.BindMachineBossContract;
import jgl.vajra.operator.part.login.model.BindMachineBossModel;
import jgl.vajra.operator.widget.bean.BaseRequestData;
import jgl.vajra.operator.widget.mvvm.factory.CreateModel;
import jgl.vajra.operator.widget.retrofithelper.rxsubscriber.ProgressObserver;
import jgl.vajra.operator.widget.utils.ToastUtils;

@CreateModel(BindMachineBossModel.class)
public class BindMachineBossViewModel extends BindMachineBossContract.ViewModel{

    @Override
    public void getVerifyCode(Map<String, Object> map) {
        mModel.getVerifyCode(map).subscribe(new ProgressObserver<BaseRequestData<String>>(false, null) {
            @Override
            public void _onNext(BaseRequestData<String> data) {
                ToastUtils.showShort(TextUtils.isEmpty(data.data)?data.msg:data.data);
                mView.returnVerifyCodeData(data.code);
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
                ToastUtils.showShort(errorMessage);
                mView.returnVerifyCodeData(errorCode);
            }
        });
    }

    @Override
    public void bindMachineData(Map<String, Object> map) {
        mModel.bindMachineData(map).subscribe(new ProgressObserver<Object>(true, null) {
            @Override
            public void _onNext(Object secretKey) {
               mView.returnBindMachineData();
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
                ToastUtils.showShort(errorMessage);
            }
        });
    }
}
